﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:ed="http://schemas.microsoft.com/expression/2010/drawing"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             xmlns:models="clr-namespace:ReporterControlLibrary.Models;assembly=ReporterControlLibrary"
			 xmlns:converters="clr-namespace:Reporter.Converters" 
             xmlns:controls="clr-namespace:Reporter.Controls" 
             xmlns:ReporterControlLibrary="clr-namespace:ReporterControlLibrary;assembly=ReporterControlLibrary" 
             x:Name="userControl"
             x:Class="Reporter.Controls.ProjectTplListBoxItem"
			 mc:Ignorable="d" >
    <UserControl.Resources>

        <converters:BoolToBrushConverter x:Key="ReportInfoValidationConverter" SourceValue="True" MatchValue="{StaticResource ValidReportInfoBrush}" MisMatchValue="{StaticResource InvalidReportInfoBrush}"/>
        <!--<converters:BoolToVisibilityConverter x:Key="BoolToNegativeVisibilityConverter" SourceValue="True" MatchValue="Collapsed" MisMatchValue="Visible" />-->
        <converters:IntToVisibilityConverter x:Key="ItemsCountToVisibilityConverter" SourceValue="0" MatchValue="Collapsed" MisMatchValue="Visible"/>
        <converters:IntToVisibilityConverter x:Key="ReportPercentToVisibilityConverter" SourceValue="-1" MatchValue="Collapsed" MisMatchValue="Visible" />
        <converters:IntToBoolConverter x:Key="ReportPercentToBoolConverter" SourceValue="-1" MatchValue="False" MisMatchValue="True" />

    </UserControl.Resources>

    <Grid Height="Auto" Width="Auto" SnapsToDevicePixels="True">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="0"/>
            <ColumnDefinition Width="63.333"/>
            <ColumnDefinition Width="300"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition Width="Auto" MinWidth="99"/>
            <ColumnDefinition Width="Auto" MinWidth="60"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="0.5*"/>
            <RowDefinition Height="0.5*"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
        </Grid.RowDefinitions>
        <Rectangle x:Name="Background" IsHitTestVisible="False" Fill="{Binding IsValid, Converter={StaticResource ReportInfoValidationConverter}, Mode=OneWay}" RadiusX="3" RadiusY="3" Grid.ColumnSpan="8" Grid.RowSpan="2"/>
        <Rectangle x:Name="BackgroundShine" IsHitTestVisible="False" Opacity="0.2" Fill="{DynamicResource ShineBrush}" RadiusX="3" RadiusY="3" Grid.ColumnSpan="8" Grid.RowSpan="2" Grid.Column="1" d:LayoutOverrides="GridBox"/>
        <Rectangle x:Name="HoverRectangle" IsHitTestVisible="False" Opacity="0" Fill="{DynamicResource NormalBrush}" RadiusX="1" RadiusY="1" Grid.ColumnSpan="6" Grid.RowSpan="2"/>
        <Rectangle x:Name="SelectedRectangle" IsHitTestVisible="False" Opacity="0" Fill="{DynamicResource SelectedBackgroundBrush}" RadiusX="1" RadiusY="1" Grid.ColumnSpan="6" Grid.RowSpan="2" Margin="0"/>
        <TextBox x:Name="TemplateFile_tb" KeyUp="TemplateInfoChanged" LostFocus="TemplateLostFocus" Grid.Column="2" Grid.RowSpan="1" TextWrapping="Wrap" d:LayoutOverrides="Height" Width="Auto" Margin="0,2,0,1" Text="{Binding TemplateName, Mode=TwoWay, UpdateSourceTrigger=Explicit}"/>
        <TextBox x:Name="ResultFile_tb" KeyUp="TemplateInfoChanged" LostFocus="TemplateLostFocus" Grid.Column="2" Grid.RowSpan="1" TextWrapping="Wrap" d:LayoutOverrides="Width, Height" Grid.Row="1" Margin="0,1,0,2" Text="{Binding ResultName, Mode=TwoWay, UpdateSourceTrigger=Explicit}"/>
        <TextBlock Grid.Row="0" TextWrapping="Wrap" Text="Template" VerticalAlignment="Center" Foreground="#FFF3FEF4" HorizontalAlignment="Left" Grid.Column="1" Margin="5,0,0,0" Style="{DynamicResource FormLabelStyle}"/>
        <TextBlock Grid.Row="1" TextWrapping="Wrap" Text="Result" VerticalAlignment="Center" Foreground="#FFF3FEF4" HorizontalAlignment="Left" Grid.Column="1" Margin="5,0,0,0" Style="{DynamicResource FormLabelStyle}"/>
        <Button x:Name="OpenTemplate_bt" Margin="5,0,0,0" Width="19" HorizontalAlignment="Left" IsCancel="True" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Height="19" VerticalAlignment="Center" d:LayoutOverrides="Height" Grid.Column="3">
        	<i:Interaction.Triggers>
        		<i:EventTrigger EventName="Click">
        			<i:InvokeCommandAction Command="{Binding OpenTemplateCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
        		</i:EventTrigger>
        	</i:Interaction.Triggers>
        	<Canvas Height="10.5" Width="10.5">
        		<Ellipse HorizontalAlignment="Stretch" Height="6.563" Margin="0" Stroke="White" StrokeThickness="1" VerticalAlignment="Stretch" Width="6.564"/>
        		<Rectangle HorizontalAlignment="Stretch" Height="5.756" Margin="0" RadiusY="1" RadiusX="1" StrokeThickness="1" VerticalAlignment="Stretch" Width="1.851" Canvas.Left="6.818" Canvas.Top="4.824" Fill="White" RenderTransformOrigin="0.5,0.5">
        			<Rectangle.RenderTransform>
        				<TransformGroup>
        					<ScaleTransform/>
        					<SkewTransform/>
        					<RotateTransform Angle="-46.789"/>
        					<TranslateTransform/>
        				</TransformGroup>
        			</Rectangle.RenderTransform>
        		</Rectangle>
        	</Canvas>
        </Button>

        <Button x:Name="OpenResult_bt" Grid.ColumnSpan="1" Grid.Column="3" Grid.Row="1" Margin="5,0,0,0" HorizontalAlignment="Left" ToolTip="Open result in MS Word" Width="19" Height="19">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <i:InvokeCommandAction Command="{Binding OpenResultCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <Canvas Height="10.5" Width="10.5">
                <Ellipse HorizontalAlignment="Stretch" Height="6.563" Margin="0" Stroke="White" StrokeThickness="1" VerticalAlignment="Stretch" Width="6.564"/>
                <Rectangle HorizontalAlignment="Stretch" Height="5.756" Margin="0" RadiusY="1" RadiusX="1" StrokeThickness="1" VerticalAlignment="Stretch" Width="1.851" Canvas.Left="6.818" Canvas.Top="4.824" Fill="White" RenderTransformOrigin="0.5,0.5">
                    <Rectangle.RenderTransform>
                        <TransformGroup>
                            <ScaleTransform/>
                            <SkewTransform/>
                            <RotateTransform Angle="-46.789"/>
                            <TranslateTransform/>
                        </TransformGroup>
                    </Rectangle.RenderTransform>
                </Rectangle>
            </Canvas>
        </Button>
        <Button x:Name="BrowseTemplate_bt" Margin="5,0,0,0" Grid.ColumnSpan="1" Content="..." Grid.Column="4" Grid.RowSpan="1" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Center" Padding="1,0" VerticalContentAlignment="Center" Width="19" Height="19" ToolTip="Browse for project template file" IsEnabled="{Binding IsGenerating, Converter={StaticResource BoolToNegativeBoolConverter}, ElementName=userControl}">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Click">
                    <i:InvokeCommandAction Command="{Binding BrowseProjectTemplateCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Button>

        <StackPanel Grid.Column="7" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Grid.RowSpan="2" Margin="0,0,3,0">
            <Button x:Name="addTemplateButton" Content="+" Visibility="{Binding IsLastItem, Converter={StaticResource BoolToVisibilityConverter}}" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Left" VerticalContentAlignment="Center" d:LayoutOverrides="GridBox" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Add new project template" IsEnabled="{Binding IsGenerating, Converter={StaticResource BoolToNegativeBoolConverter}, ElementName=userControl}"  >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding AddProjectTemplateCommmand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button x:Name="removeTemplateButton" Content="-" Margin="5,0,0,0" VerticalAlignment="Center" HorizontalContentAlignment="Center" HorizontalAlignment="Left" VerticalContentAlignment="Center" d:LayoutOverrides="GridBox" Width="19" Height="19" Padding="1,-2,1,1" FontSize="16" ToolTip="Remove this project template" IsEnabled="{Binding IsGenerating, Converter={StaticResource BoolToNegativeBoolConverter}, ElementName=userControl}"  >
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding DeleteProjectTemplateCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>

        </StackPanel>
        <Rectangle x:Name="FocusVisualElement" Stroke="{DynamicResource HoverShineBrush}" StrokeThickness="1" RadiusX="1" RadiusY="1" Opacity="0" Grid.ColumnSpan="6" Grid.RowSpan="2" ToolTip="Open project template in MS Word" d:IsHidden="True"/>
        <Rectangle Grid.Column="0" HorizontalAlignment="Stretch" Margin="10.875,10.959,-7.125,10.419" RadiusY="2" RadiusX="2" Grid.RowSpan="2" Width="Auto" Stroke="Black" Clip="M-40.25,-15.209 L10.5,-15.209 L10.5,44.791 L-40.25,44.791 z" Visibility="Collapsed"/>
        <ToggleButton Visibility="Collapsed" x:Name="reportLogToggleButton" Content="?" Grid.Column="4" Grid.Row="1" Width="19" Height="19" VerticalContentAlignment="Center" Padding="0"/>


        <Expander x:Name="evalModelExpander" Header="Evaluate Template Path" d:LayoutOverrides="Height" Grid.ColumnSpan="8" Grid.Row="2" Style="{DynamicResource ReportInfoExpanderStyle}" Background="{DynamicResource ControlBackgroundBrush}">
            <Grid>
                <ReporterControlLibrary:EvalModelPath x:Name="evalModelPath" DataContext="{Binding}" d:LayoutOverrides="Height" MaxHeight="400" />
            </Grid>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="Expanded">
                    <i:InvokeCommandAction Command="{Binding EvalModelExpandedCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding}"/>
                </i:EventTrigger>
                <i:EventTrigger EventName="Collapsed">
                    <i:InvokeCommandAction Command="{Binding EvalModelCollapsedCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
        </Expander>
        <Expander x:Name="reportLogExpander" Header="Report Log" d:LayoutOverrides="Height" Grid.ColumnSpan="8" Grid.Row="3" IsExpanded="{Binding IsChecked, ElementName=reportLogToggleButton}" Style="{DynamicResource ReportInfoExpanderStyle}" Background="{DynamicResource TextBrush}">
            <Grid>
                <ListBox HorizontalAlignment="Stretch" d:LayoutOverrides="GridBox" MaxHeight="200" ItemsSource="{Binding ReportLogs}" ItemTemplateSelector="{StaticResource reportLogDataTemplateSelector}" Background="{x:Null}" Margin="0" VerticalContentAlignment="Top" ItemContainerStyle="{DynamicResource ReportLogListBoxItemContainerStyle}" ScrollViewer.CanContentScroll="False" />
            </Grid>
        </Expander>

        <StackPanel Grid.Column="5" Orientation="Horizontal" d:LayoutOverrides="Height" Grid.RowSpan="2" Margin="15,0,0,0" HorizontalAlignment="Left">
            <!--<Button x:Name="generateButton" Content="Generate" VerticalAlignment="Center" HorizontalAlignment="Center" Height="25" Padding="5,1" Click="GenerateButtonClick" IsEnabled="{Binding IsValid}"/>-->
            <Button x:Name="generateButton" Content="Report" VerticalAlignment="Center" HorizontalAlignment="Left" Height="26" Padding="5,1" Style="{DynamicResource ReportButtonStyle}">
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding StartReportingCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <Button x:Name="paramsButton" Content="Params" VerticalAlignment="Center" HorizontalAlignment="Left" Height="25" Padding="5,1" Margin="5,0,0,0">
                <!--Visibility="{Binding ReportParameters.Count, Converter={StaticResource ItemsCountToVisibilityConverter}}"-->
                <i:Interaction.Triggers>
                    <i:EventTrigger EventName="Click">
                        <i:InvokeCommandAction Command="{Binding SetTemplateParametersCommand, Mode=OneWay, Source={StaticResource ApplicationManager}}" CommandParameter="{Binding Mode=OneWay}"/>
                    </i:EventTrigger>
                </i:Interaction.Triggers>
            </Button>
            <CheckBox x:Name="autoOpenResultCheckBox" Content="Auto open result" IsChecked="{Binding AutoOpenResult, Mode=TwoWay}" VerticalAlignment="Center" Margin="5,0,0,0" /> 
            <!--<controls:CircularPercentualProgressBar Visibility="{Binding IsReporting, Converter={StaticResource BoolToVisibilityConverter}}" FinishedPercentage="{Binding FinishedPercentage}" ShowPercentage="False" Margin="5,0,0,0"/>-->
            <controls:CircularProgressBar x:Name="Preloader" Height="14" Width="14" Visibility="{Binding IsReporting, Converter={StaticResource BoolToVisibilityConverter}}"  Margin="5,0,0,0" HorizontalAlignment="Left" VerticalAlignment="Center"/>
        </StackPanel>
    </Grid>
</UserControl>
